package com.mall.service.authority.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.model.domain.UmsAdmin;
import com.mall.model.vo.PageResult;
import com.mall.service.authority.mapper.UmsAdminMapper;
import com.mall.service.authority.service.UmsAdminService;
import org.apache.commons.lang.StringUtils;

import org.springframework.stereotype.Service;

@Service
public class UmsAdminServiceImpl extends ServiceImpl<UmsAdminMapper, UmsAdmin> implements UmsAdminService {

    @Override
    public PageResult getList(Integer page, Integer pageSize, String keyword) {
        Page<UmsAdmin> adminPage = new Page<>(page, pageSize);

        LambdaQueryWrapper<UmsAdmin> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(keyword),UmsAdmin::getNickName,keyword).or()
        .like(StringUtils.isNotEmpty(keyword),UmsAdmin::getUsername,keyword);
        Page<UmsAdmin> pageInfo = super.page(adminPage, queryWrapper);

        return new PageResult(page,pageSize, (int) pageInfo.getTotal(),pageInfo.getRecords());
    }
}
